package com.ljw.community.mapper;

import com.ljw.community.entity.Comment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper {

    @Select(value = "SELECT c.*,u.login_name creator_login_name FROM comment c,user u " +
            "where topic_id = #{topicId} AND c.creator_id = u.id AND c.del_flag='0' order by c.create_time")
    List<Comment> loadCommentsByTopicId(String topicId);

    @Insert(value = "insert into comment(id,content,topic_id,creator_id,reply_id,create_time)" +
            "values(#{id},#{content},#{topicId},#{creatorId},#{replyId},#{createTime})" )
    int insert(Comment comment);

    //计算话题中的留言数
    @Select(value = "select count(1) from comment where topic_id = #{topicId} and del_flag ='0'")
    int countByTopicId(String topicId);
}
